<?php
class ViewHelper {
	
	public static function renderTopTools() {
		$html = '<h3 class="form-legend">';
		$html .= '<i class="bicon-goright"></i>';
		$html .= '<span>'. Yii::t('app', Yii::app()->controller->pageTitle) .'</span>';
		$html .= '<i class="clear"></i>';
		$html .= '</h3>';
		$html .= '<div class="top-tools">';
		$html .= ViewHelper::backButton();
		$html .= '<div class="pull-right">';
        $html .= ViewHelper::formGroupButton();
    	$html .= '</div>';
    	$html .= '<div class="clear"></div></div>';
    	return $html;
	}
	
	public static function renderTopToolsList() {
		$html = '<h3 class="form-legend">';
		$html .= '<i class="bicon-goright"></i><span>'. Yii::t('app', Yii::app()->controller->pageTitle) .'</span>';
		$html .= '	<i class="clear"></i>';
		$html .= '</h3>';
		$html .= '<div class="top-tools">';
		$html .= ViewHelper::backButton();
		$html .= '<div class="pull-right">';
		$html .= '<a class="btn btn-success" href="'. Yii::app()->createUrl( 'admin/'. Yii::app()->controller->id .'/create'). '">';
		$html .= '<i class="icon-file icon-white"></i>'. Yii::t('app', 'create');
		$html .= '</a>';
		$html .= '</div>';
		$html .= '<div class="clear"></div>';
		$html .= '</div>';
		return $html;
	}
	
	public static function backButton($label=null, $url=null, $htmlOptions=array(), $return=true) {
		$url =  $url != null 
		? $url 
		: (Yii::app()->controller->backUrl != null 
				? Yii::app()->controller->backUrl 
				: Yii::app()->request->getUrlReferrer());
		$label = $label != null ? $label : Yii::t('app', 'Back');
		$htmlOptions = $htmlOptions + array('class' => 'btn');
		
		$btn = CHtml::link($label, $url, $htmlOptions);
		if($return) {
			return $btn;
		}
		echo $btn;
	}
	
	public static function formGroupButton() {
		$groupButton = '<div class="form-group-button">';
		$groupButton .= ViewHelper::formSubmitButton();
		$groupButton .= ViewHelper::formResetButton();
		$groupButton .= '</div>';
		return $groupButton;
	}
	
	public static function formSubmitButton() {
		return CHtml::submitButton(Yii::t('app', 'Submit'), array('data-oe-form-action' => 'Submit', 'class' => 'btn btn-primary'));
	}
	
	public static function formResetButton() {
		return CHtml::resetButton(Yii::t('app', 'Reset'), array('data-oe-form-action' => 'Reset', 'class' => 'btn'));
	}

	
	public static function getBreadcrumb() {
		$controller = Yii::app()->controller;
		$controllerName = $controller->id;
		$actionName = $controller->getAction()->id;
		$pageTitle = $controller->pageTitle;
		
		$lastTitle = null;
		switch ($actionName) {
			case 'index':
				$lastTitle = 'Manage';
			break;
			
			case 'create':
				$lastTitle = 'Create';
			break;
			
			case 'create':
				$lastTitle = 'Update';
			break;
		}
		
		$breadcrumb = array(
				$pageTitle => array($actionName),
				Yii::t('app', $lastTitle),
		);
		return $breadcrumb;		
	}
	
}